import os
import re

# Base directory containing the numbered folders
BASE_DIR = "./EMOGNITION"

# Define the patterns
pattern1 = re.compile(r"^\d+_[a-zA-Z]+_[a-zA-Z]+_EMPATICA\.json$")
pattern2 = re.compile(r"^\d+_QUESTIONNAIRES\.json$")

# Iterate over each folder in the base directory
for folder in os.listdir(BASE_DIR):
    folder_path = os.path.join(BASE_DIR, folder)
    if os.path.isdir(folder_path):
        # Iterate over each file in the folder
        for file_name in os.listdir(folder_path):
            file_path = os.path.join(folder_path, file_name)
            # Check if the file name matches either of the patterns
            if not (pattern1.match(file_name) or pattern2.match(file_name)):
                # Remove the file if it does not match the patterns
                os.remove(file_path)
                print(f"Removed: {file_path}")